package com.controller;


import com.dto.excution.ListExcution;
import com.entity.BillInfo;
import com.entity.MoneyInfo;
import com.enums.ListEnum;
import com.service.BillService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RequestMapping("bill")
@RestController
public class BillController {

    @Autowired
    private BillService service;

    @ApiOperation(value = "查看用户余额")
    @PostMapping(value = "/findUserMoney")
    @ResponseBody
    public ListExcution findUserMoney(Integer userId){
        MoneyInfo money = service.findUserMoney(userId);
        return new ListExcution(money, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查看收入和支出")
    @PostMapping(value = "/findBillList")
    @ResponseBody
    public ListExcution<List<BillInfo>> findBillList(Integer userId,Integer limit){
        List<BillInfo> list = service.findBillList(userId,limit);
        return new ListExcution<List<BillInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "新增流水")
    @PostMapping(value = "/insertBill")
    @ResponseBody
    public ListExcution<Void> insertBill(Integer userId,BigDecimal money,Integer types,String description){
        int count = service.insertBill(userId,money,types,description);
        if(count > 0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else{
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

}
